<?php $this->_extends('_layouts/default_layout'); ?>
 
<?php $this->_block('contents'); ?>


<span><a href="<?php echo url('user/AddMember'); ?>">企业用户添加</a> | <a href="<?php echo url('user/manage'); ?>">企业用户管理</a>
<?php if ($current_user->permission_id == 2): ?> |  <a href="<?php echo url('user/ContentManage'); ?>">企业内容审核员管理</a><?php endif; ?><?php if ($current_user->permission_id == 1): ?> | <a href="<?php echo url('user/AddManager'); ?>">电信管理员添加</a> | <a href="<?php echo url('user/tianyimanage'); ?>">电信管理员管理</a><?php endif; ?>	</span>

<br /><br />


<div>
<form autocomplete="off" method="post" name="mainform" enctype="multipart/form-data" >

<span>&nbsp;&nbsp;手机号码搜索用户：<input type="text" id="phone" autocomplete="off" onkeyup="beKeyUp();" /></span> <br/><br/>
<div id="">&nbsp;&nbsp;您搜索的用户：<div id="search_suggest" style=""></div></div>
</form>
</div>
<br /><br />


<script type="text/javascript">
var xmlHttp = null;
function makeAjax() {     
    var xmlHttp=null;
    try{        
        xmlHttp = new XMLHttpRequest();    
    }     
    catch (e) 
    {         
        try 
        {  
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");        
        }
        catch (e) 
        {            
            try {    
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");            
            }            
            catch (e) 
            {                 
                alert("Your browser is either OLD or BAD! UPDATE!");
                return xmlHttp;             
            }         
        }     
    }     
    return xmlHttp;
} 


var array=new Array(); //定义一个全局变量数组，用来存放拆分字符串的值，后面具体介绍。

function beKeyUp()
{
    var key = document.getElementById("phone").value;
    if(key.length>0)//有值才POST，这里最好加个Trim()方法，但是JAVASCRIPT没有现成的方法，自己定义。
    {
        xmlHttp = makeAjax();
        var url = "<?php echo url('user/searchuser'); ?>";
        var poststr="&user_phone=" + escape(key);
        //alert(url);
        // Open a connection to the server
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");

        // Setup a function for the server to run when it's done
        xmlHttp.onreadystatechange = stateChange;

        // Send the request
        xmlHttp.send(poststr);
    }
}
function stateChange()
{
    if (xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
    {
        var responseStr=xmlHttp.responseText;//获取返回值
        if(responseStr.length>0)//返回值不为空才执行下面的代码
        {
            //alert(responseStr);
            array=responseStr.split('|');//根据‘|’拆分，根据自己任意特殊字符，初始化数组
            document.getElementById("search_suggest").innerHTML="&nbsp;&nbsp;";//每次清空DIV内容
            var bflag=0;
            for(var i=0;i<array.length;i++)
            {
                if(i == 0)
                {
                    continue;
                }
                if(array[i]!="")//项值不为空，组合DIV，每个DIV有onmouseover、onmouseout、onclick对应事件
                {
                    document.getElementById("search_suggest").innerHTML += array[i];
                    bflag=1;
                }
            }
            if(bflag)
            {
                var httplink = "<?php echo url('user/edit'); ?>"+ "&user_id="+array[0];
                var del_httplink = "<?php echo url('user/DeleteItem'); ?>"+ "&user_id="+array[0];
                <?php if ($current_user->permission_id == 1): ?>
                document.getElementById("search_suggest").innerHTML +="<a href=\""+del_httplink+"\"; onclick= 'return del()' >"+"&nbsp;&nbsp;&nbsp;删除"+"</a>";
                <?php else: ?>
                document.getElementById("search_suggest").innerHTML += "<a href=\""+httplink+"\"; >"+"&nbsp;&nbsp;&nbsp;编辑"+"</a>" + "&nbsp;&nbsp;&nbsp;<a href=\""+del_httplink+"\"; onclick= 'return del()' >"+"&nbsp;&nbsp;&nbsp;删除"+"</a>";
                <?php endif; ?>
            }
            document.getElementById("search_suggest").style.display="inline";
        }
        else
        {
            document.getElementById("search_suggest").style.display="inline";
            document.getElementById("search_suggest").innerHTML="&nbsp;&nbsp;您查找的用户不存在";
        }
    }
}
</script>



<form action="<?php echo url('user/Delete'); ?>" method="post" name="mainform" enctype="multipart/form-data" >
	<table cellpadding="0" cellspacing="0" width="100%">
	<tbody class="">
		<tr class="tth">
		<td width="24%">选择</td>
		<td width="30%">用户名</td>
	<?php if ($current_user->permission_id == 2): ?>
		<td width="30%">用户实名</td>
	<?php elseif ($current_user->permission_id == 1): ?>
		<td width="30%">用户企业</td>
	<?php endif; ?>	
		<td width="*"></td>
	<?php foreach ($users as $user): ?>		
		</tr>
			<tr>
			<td><input type="checkbox" name="checkboxid[]"  id="checkboxid" value="<?php echo $user->id() ?>" /></td>
			<td><?php echo $user->username ?></td>
	<?php if ($current_user->permission_id == 2): ?>
			<td><?php echo $user->user_realname ?></td>
			<td><a href="<?php echo url('user/edit', array('user_id' => $user->id())); ?>">[编辑]</a></td>
	<?php elseif ($current_user->permission_id == 1): ?>
			<td><p><?php echo $user->getEnterpriseName(); ?></p></td>
			<td></td>
	<?php endif; ?>	
		</tr>
	<?php endforeach; ?>	
	
	</tr>

	</tbody>
	<tr>
		<td class="tbutton" colspan="6"><input type="button" value="全选" class="btn" name="choseall" id="Name" onclick="SelectAll()">&nbsp;<input type="submit" onClick="return(CheckFirst())" value="删除" class="btn" name="submit"></td>
	</tr>
	</table>
</form>
<script>
	function SelectAll() {
	 var flg=0;
	 var checkboxs=document.getElementsByName("checkboxid[]");
	 var count=0;
	 for (var j=0; j<checkboxs.length; j++)
	 {
		var e=checkboxs[j];
		if(e.checked)count++;
	 }
	 if(count < checkboxs.length)
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =1;
			 flg= true;
		 }
	 }
	 else 
	 {
		 for (var i=0;i<checkboxs.length;i++) {
			 var e=checkboxs[i];
			 e.checked =0;
			 flg= false;
		 }

	 }

	 if (flg)
	 {
		document.mainform.choseall.value = "取消";
	 }
	 else
	 {
		document.mainform.choseall.value = "全选";
	 }

	}
    function   del() 
    { 
        if(confirm( "是否确定要删除? ")) 
            return   true; 
        else 
            return   false; 
    } 

	function CheckFirst()
	{
	    var count=0;
        var checkboxs=document.getElementsByName("checkboxid[]");
	    for (var i=0;i<checkboxs.length;i++)
		{
		    var e=checkboxs[i];
		    if(e.checked)count++;
	    }
        if(count == 0)
		{
			alert('请先选择删除条目'); 
			return false;
		}
		else
		{
            if(!confirm('您确认要删除吗?')) 
                return false;
            else
                return true; 
		}
	}
</script>
<?php $this->_control('pagination', 'my-pagination', array('pagination' => $pagination)); ?>

<?php $this->_endblock(); ?>
